import com.young.shop.api.dao.UserMapper;
import com.young.shop.pojo.entity.Address;
import com.young.shop.pojo.entity.User;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.web.WebAppConfiguration;

import java.util.List;

/**
 * @author 曾家乐
 * @version 1.0
 * @date 2021-01-08 16:42
 */
@WebAppConfiguration
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration({"classpath:spring-context.xml"
        , "classpath:spring-druid.xml"
        , "classpath:spring-mybatis.xml"})
public class UserController {
    @Autowired
    private UserMapper userMapper;

    @Test
    public void test01(){
        User user = userMapper.selectByUserName("23123");
        System.out.println(user);
    }

    @Test
    public void test02(){
        User user = new User();
        user.setUserName("xiaozz");
        user.setPassword("Qpf0SxOVUjUkWySXOZ16kw");
        user.setEmail("123123@qqq.com");
        int result = userMapper.insertUser(user);
        Assert.assertEquals(1,result);
    }

    @Test
    public void test03(){
        User user = new User();
        user.setEmail("1212@qqq.com");
        user.setUserName("23");
        User user1 = userMapper.selectByUser(user);
        System.out.println(user1);
    }

    @Test
    public  void test04(){
        Address address = new Address();
        address.setUserId(31);
        address.setName("zjl");
        address.setPhone("1111111111111111111");
        address.setProvince("山东省");
        address.setCity("滨州市");
        address.setDist("滨城区");
        address.setAddress("dizhi");
        int i = userMapper.insertAddress(address);
        Assert.assertEquals(1,i);
    }

    @Test
    public  void test05() {
        List<Address> addresses = userMapper.selectAddressByUserId(31L);
        addresses.forEach(item->{
            System.out.println(item);
        });
    }


    @Test
    public void test06() {
        User user = new User();
        user.setEmail("1212@qqq.com");
        user.setUserName("23");

        User user1 = new User();
        user1.setEmail("1212@qqq.com");
        user1.setUserName("24");

        System.out.println(user.equals(user1));
    }


}
